//
//  MainFuncItemVM.swift
//  kxf
//
//  Created by Mac on 2024/3/9.
//

import Foundation
import UIKit

class MainFuncItemVM: UIView {
    
    let selfHeight = kFitWidth(90)
    var tapBlock:(()->())?

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: frame.origin.x, y: frame.origin.y, width: selfHeight, height: selfHeight))
        self.backgroundColor = WHColor_16(colorStr: "FEF2F0")
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(12)
        self.clipsToBounds = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapAction))
        self.addGestureRecognizer(tap)
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var imgView : UIImageView = {
        let img = UIImageView()
//        img.layer.cornerRadius = kFitWidth
        img.contentMode = .scaleAspectFit
        img.isUserInteractionEnabled = true
        
        return img
    }()
    lazy var titleLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .regular)
//        lab.text = "展业中心"
        lab.textAlignment = .center
        lab.adjustsFontSizeToFitWidth = true
        
        
        return lab
    }()
}

extension MainFuncItemVM{
    @objc func tapAction() {
        if self.tapBlock != nil{
            self.tapBlock!()
        }
    }
}

extension MainFuncItemVM{
    func initUI() {
        addSubview(imgView)
        addSubview(titleLabel)
        
        setConstrait()
    }
    func setConstrait() {
        imgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(9))
            make.width.height.equalTo(kFitWidth(48))
        }
        titleLabel.snp.makeConstraints { make in
            make.left.width.equalToSuperview()
            make.bottom.equalTo(kFitWidth(-6))
        }
    }
}

